package com.example.springboot.mapper;

import com.example.springboot.entity.UserWatchRemember;
import com.example.springboot.entity.vo.PostVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserWatchRememberMapper {

    @Insert("INSERT INTO user_watch_remember (user_id, post_id, tags,created_at,updated_at) VALUES (#{userId}, #{postId}, #{tags},#{createdAt},#{updatedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(UserWatchRemember userWatchRemember);

    @Delete("DELETE FROM user_watch_remember WHERE id = #{id}")
    int deleteById(int id);

    @Update("UPDATE user_watch_remember SET user_id = #{userId}, post_id = #{postId}, tags = #{tags} WHERE id = #{id}")
    int update(UserWatchRemember userWatchRemember);

    @Select("SELECT * FROM user_watch_remember WHERE id = #{id}")
    UserWatchRemember findById(int id);

    @Select("""
SELECT
            bp.id,
            bp.content,
            bp.author_id AS authorId,
            bp.category_id AS categoryId,
            bp.tags,
            bp.updated_time AS updatedTime,
            bp.published_time AS publishedTime,
            bp.status,
            bp.views,
            bp.likes,
            bp.comments_count AS commentsCount,
            bp.collect_count AS collectCount,
            bp.article_type AS articleType,
            bp.cover,
            bp.title,
            bp.summary
        FROM user_watch_remember uwr
        INNER JOIN blog_posts bp ON uwr.post_id = bp.id
        WHERE uwr.user_id = #{userId}
        ORDER BY uwr.id DESC
        LIMIT #{pageSize} OFFSET #{pageNum}
""")
    List<PostVo> findByUserId(Integer userId, Integer pageNum, Integer pageSize);
    @Select("SELECT COUNT(1) FROM user_watch_remember WHERE user_id = #{userId}")
    Integer getUserWatchRememberNumByUserId(int userId);
}